﻿using System;
using System.Diagnostics;
using Slf;

namespace Redirecting_Trace_To_SLF
{
  class Program
  {
    static void Main(string[] args)
    {
      //we could configure Trace  programmatically
      //however, for this sample, the listener was configured in app.config
      //here's how you would do it in code:
      //Trace.Listeners.Add(new SlfTraceListener());

      Console.ForegroundColor = ConsoleColor.Green;
      Console.Write("In this sample, we are logging to Trace, not SLF. However, Trace itself was configured with an SLF listener, ");
      Console.WriteLine("so everything will be redirected to SLF behind the scenes.\n\n");
      Console.ResetColor();

      //configure SLF with a logger
      //(NOT TraceLogger, or you'll end up with a recursive routine that crashes your machine!) 
      var logger = new DelegateLogger(li => Console.WriteLine("Message received in SLF: " + li.Message));
      LoggerService.SetLogger(logger);  

      //write to Trace -> this will be redirected to our above DelegateLogger we plugged into SLF
      Trace.WriteLine("Hello Trace.");

      Console.ReadLine();
    }
  }
}
